package com.example.sls.mapper.teacher.publish;

import com.example.sls.pojo.teacher.proSet.ProSet;
import com.example.sls.pojo.teacher.publish.Publish;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface PublishMapper {

    //发布题集
    @Insert("insert into publish values(#{id}, #{setId}, #{classId}, #{publishDate})")
    Integer publishSet(Publish publish);

    //在该班级内删除已发布的题集
    @Delete("delete from publish where setId = #{setId} and classId = #{classId}")
    Integer deleteSet(@Param("setId") Integer setId, @Param("classId") Integer classId);


    //查看在指定班级发布的所有题集(分页)
    @Select("select * from publish where classId = #{classId}")
    List<Publish> getPublishInfoByCId(@Param("classId") Integer classId);

    //查看所有发布信息(分页)
    @Select("select * from publish ")
    List<Publish> getPublishInfo();

    //查看当前老师创建的、未在当前班级发布的题集信息(分页)
    @Select(" select * from proset where createdBy = #{teacherId} and setId not in (select setId from publish where classId = #{classId}) ")
    List<ProSet> getUnpublishedProset(@Param("teacherId") Integer teacherId, @Param("classId") Integer classId );

    //查看当前老师创建的、未在当前班级发布的题集题号
    @Select(" select setId from proset where createdBy = #{teacherId} and setId not in (select setId from publish where classId = #{classId}) order by setId asc; ")
    List<Integer> getUnpublishedSetId(@Param("teacherId") Integer teacherId, @Param("classId") Integer classId );

    @Select("select max(id) from publish")
    Integer getMaxId();

    @Select("select count(*) from publish")
    Integer getCount();


}
